package org.zsqx.tools;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import cDao.bean.PageBean;


public class PageDiv extends TagSupport {
	PageBean pageBean;
	private String url = "";
	private String para = "";
	private boolean second = false; 
	private String cssClass = "paging";
	public PageBean getPageBean() {
		return pageBean;
	}
	public void setPageBean(PageBean pageBean) {
		this.pageBean = pageBean;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public String getPara() {
		return para;
	}
	public void setPara(String para) {
		this.para = para;
	}
	public String getCssClass() {
		return cssClass;
	}
	public void setCssClass(String cssClass) {
		this.cssClass = cssClass;
	}
	public boolean isSecond() {
		return second;
	}
	public void setSecond(boolean second) {
		this.second = second;
	}
	@Override
	public int doStartTag() throws JspException {
		JspWriter out = pageContext.getOut();
		String type = "";
		if(isSecond()){
			type = "2";
		}
		Integer currentPage = pageBean.getCurrentPage();
		Integer pageCount  = pageBean.getPageCount();
		
		try {
			out.print("<div class='"+cssClass+"'>");
			if(currentPage==1){
				out.print("<font color='gray'>首页 | 上一页 </font>");
			}else{
				out.print("<a href='"+url+"?currentPage"+type+"=1&"+para+"'>首页</a> | ");
				out.print("<a href='"+url+"?currentPage"+type+"="+(currentPage-1)+"&"+para+"'>上一页</a> | ");
			}
			if(currentPage==pageCount){
				out.print("<font color='gray'> 下一页 | 尾页 </font>");
			}else{
				out.print("<a href='"+url+"?currentPage"+type+"="+(currentPage+1)+"&"+para+"'>下一页</a> | ");
				out.print("<a href='"+url+"?currentPage"+type+"="+pageCount+"&"+para+"'>尾页</a>");
			}
			out.print("&nbsp;&nbsp;&nbsp;&nbsp;");
			out.print("当前第"+currentPage+"页 | ");
			out.print("共"+pageCount+"页");
			out.print("</div>");
		} catch (IOException e) {
			System.out.println("分页出错！");
			e.printStackTrace();
		}
		return super.doStartTag();
	}

}
